<template>
  <el-drawer
    @close="close"
    :visible.sync="dialogVisible"
    :title="title"
    :size="500"
  >
    <el-row :gutter="10" class="box-card">
      <el-form ref="elForm" :model="formData" :rules="rules" size="small" label-width="80px">
        <el-col :span="24">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="formData.name" placeholder="请输入姓名" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="年龄" prop="age">
            <el-input v-model="formData.age" placeholder="请输入年龄" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="formData.sex" size="medium">
                <el-radio v-for="(item, index) in sexOptions" :key="index" :label="item.value">
                  {{item.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
         <el-col :span="24">
          <el-form-item label="民族" prop="minzu">
            <el-input v-model="formData.minzu" placeholder="请输入民族" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="身份证号" prop="sfz">
            <el-input v-model="formData.sfz" placeholder="请输入身份证" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="电话" prop="phone">
            <el-input v-model="formData.phone" placeholder="电话" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="学历" prop="xueli">
            <el-input v-model="formData.xueli" placeholder="学历" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="特长" prop="techang">
            <el-input v-model="formData.techang" placeholder="特长" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="detail">
            <el-input
              type="textarea"
              :rows="4"
              placeholder="请输入备注"
              v-model="formData.detail"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div class="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handelConfirm">确定</el-button>
    </div>
  </el-drawer>
</template>
<script>
import { saveRlzyk } from '@/api/rlzyk'
export default {
  props: [],
  data () {
    return {
      dialogVisible: false,
      formData: {
        name: '', // 姓名
        sex: 1, // 性别
        age: '', // 年龄
        minzu: '', // 民族
        sfz: '', // 身份证号
        phone: '', // 电话
        xueli: '', // 学历
        techang: '', // 特长
        detail: '' // 备注
      },
      rules: {
        name: [{
          required: true,
          message: '请输入姓名',
          trigger: 'blur'
        }]
      },
      sexOptions: [{
        label: '男',
        value: 1
      }, {
        label: '女',
        value: 0
      }],
      title: '新增人力资源',
      id: null,
      isEdit: false
    }
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    /**
     *
     * @param {*} isEdit 是否编辑
     * @param {*} data 编辑时需要的数据
     */
    async isShow (data, isEdit = false) {
      this.dialogVisible = true
      this.title = isEdit ? '编辑人力资源' : '新增人力资源'
      this.isEdit = isEdit
      await this.$nextTick()
      if (isEdit) {
        const formData = this.formData
        for (const key in formData) {
          formData[key] = data[key]
        }
        this.id = data.rlzyId
      }
    },
    close () {
      this.$refs.elForm.resetFields()
      this.dialogVisible = false
    },
    handelConfirm () {
      this.$refs.elForm.validate(async valid => {
        if (!valid) return
        this.isEdit ? (await saveRlzyk({ ...this.formData, rlzyId: this.id })) : (await saveRlzyk(this.formData))
        this.$notify.success({
          title: `完成${this.title}`
        })
        this.$emit('update:visible')
        this.close()
      })
    }
  }
}

</script>
<style lang="scss" scoped>
.box-card {
  margin-bottom: 10px;
  padding-right: 20px;
  width: 100%;
  padding-left: 10px;
}
.footer {
  display: flex;
  justify-content: space-around;
  margin-bottom: 40px;
  padding-left: 90px;
  padding-right: 20px;
  .el-button {
    width: 100%;
  }
}
</style>
